package com.polaris.live.ui.party.widget

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.bumptech.glide.Glide
import com.polaris.live.databinding.LayoutMagicLampMarqueenItemBinding
import com.polaris.live.resp.back_resp.PayerLampCarouselItem
import com.polaris.live.utils.image.ImageUtils
import com.polaris.live.utils.route.RouterUtils
import com.polaris.live.widget.marqueen.MarqueeFactory

/**
 * MagicLampMarqueeView
 *
 * @author Created by 天晴 on 2024/11/25 14:08
 * @since 1.0.0
 **/
class MagicLampMarqueeView(context: Context) : MarqueeFactory<View, PayerLampCarouselItem>(context) {

    private val inflater: LayoutInflater

    init {
        inflater = LayoutInflater.from(context)
    }

    override fun generateMarqueeItemView(data: PayerLampCarouselItem): View {
        val mBinding = LayoutMagicLampMarqueenItemBinding.inflate(inflater, null, false)

        Glide.with(mContext)
            .load(ImageUtils.imgPath(data.avatar))
            .optionalCircleCrop()
            .into(mBinding.avatar)

        val highlight = data.popupHighlight?.highlight
        if (highlight == null) {
            mBinding.shapeTv.text = data.text
        } else {
            RouterUtils.handleText(mBinding.shapeTv, data.text, highlight)
        }
        return mBinding.root
    }
}